package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Ceshi;
import com.ruoyi.system.service.ICeshiService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 管理员Controller
 * 
 * @author ruoyi
 * @date 2025-03-28
 */
@Controller
@RequestMapping("/system/ceshi")
public class CeshiController extends BaseController
{
    private String prefix = "system/ceshi";

    @Autowired
    private ICeshiService ceshiService;

    @RequiresPermissions("system:ceshi:view")
    @GetMapping()
    public String ceshi()
    {
        return prefix + "/ceshi";
    }

    /**
     * 查询管理员列表
     */
    @RequiresPermissions("system:ceshi:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Ceshi ceshi)
    {
        startPage();
        List<Ceshi> list = ceshiService.selectCeshiList(ceshi);
        return getDataTable(list);
    }

    /**
     * 导出管理员列表
     */
    @RequiresPermissions("system:ceshi:export")
    @Log(title = "管理员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Ceshi ceshi)
    {
        List<Ceshi> list = ceshiService.selectCeshiList(ceshi);
        ExcelUtil<Ceshi> util = new ExcelUtil<Ceshi>(Ceshi.class);
        return util.exportExcel(list, "管理员数据");
    }

    /**
     * 新增管理员
     */
    @RequiresPermissions("system:ceshi:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存管理员
     */
    @RequiresPermissions("system:ceshi:add")
    @Log(title = "管理员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Ceshi ceshi)
    {
        return toAjax(ceshiService.insertCeshi(ceshi));
    }

    /**
     * 修改管理员
     */
    @RequiresPermissions("system:ceshi:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Ceshi ceshi = ceshiService.selectCeshiById(id);
        mmap.put("ceshi", ceshi);
        return prefix + "/edit";
    }

    /**
     * 修改保存管理员
     */
    @RequiresPermissions("system:ceshi:edit")
    @Log(title = "管理员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Ceshi ceshi)
    {
        return toAjax(ceshiService.updateCeshi(ceshi));
    }

    /**
     * 删除管理员
     */
    @RequiresPermissions("system:ceshi:remove")
    @Log(title = "管理员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ceshiService.deleteCeshiByIds(ids));
    }
}
